<?php
/**
 * Created by PhpStorm.
 * User: Lxx<779219930@qq.com>
 * Date: 2016/4/21
 * Time: 15:58
 */

namespace app\home\controller;
use think\Config;
use think\Controller;
use think\Db;
use com\wechat\TPWechat;

class Base extends Controller {
    public function _initialize(){
//        session('userId','oJuxj0yOeMMaapUPlq5cy0dnEReA'); // 老师
        session('userId','oJuxj00BiL3gEi0wz7I0euWdRFPY'); // 学生
//        session('userId','oJuxj0xouLlU4JU3BbtQBiiBP_1k'); // 学生
//        session('header','/home/images/vistor.jpg');
//        session('nickname','游客');
        if(!empty($_SERVER['REQUEST_URI'])){
            session('url',$_SERVER['REQUEST_URI']);
        }
        $userId = session('userId');
        if(Config::get('WEB_SITE_CLOSE')){
            return $this->error('站点维护中，请稍后访问~');
        }
//        //微信认证
//        $Wechat = new TPWechat(Config::get('party'));
//        // 1用户认证是否登陆
//        if(empty($userId)) {
//            $redirect_uri =  Config::get("party.login");
//            $url = $Wechat->getOauthRedirect($redirect_uri);
//            $this->redirect($url);
//        }
//        // 2获取jsapi_ticket
//        $jsApiTicket = session('jsapiticket');
//        if(empty($jsApiTicket) || $jsApiTicket=='') {
//            session('jsapiticket', $Wechat->getJsTicket()); // 官方7200,设置7000防止误差
//        }
    }

    /**
     * 获取签名
     */
    public function jssdk(){
        $Wechat = new TPWechat(Config::get('party'));
        $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
        $jsSign = $Wechat->getJsSign($url);
        $this->assign("jsSign", $jsSign);
    }
}